
import mysql from 'mysql';
// 创建连接池
const pool = mysql.createPool({
    host: 'sh-cynosdbmysql-grp-66rrsqqm.sql.tencentcdb.com',
    port: 24051,
    user: 'root',
    password: 'Rsyong950918',
    database: 'delbug'
})

// 创建连接池 并返回一个promise
let query = function (sql: string, values?: string) {
    // 返回一个 Promise
    return new Promise<any[]>((resolve, reject) => {
        pool.getConnection(function (err, connection) {
            if (err) {
                reject(err)
            } else {
                connection.query(sql, values, (err, rows: any[]) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(rows)
                    }
                    // 结束会话
                    connection.release()
                })
            }
        })
    })
}

export default query;